<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <el-form-item label="订单编号" prop="nos">
        <el-input v-model="queryParams.nos" placeholder="请输入订单编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="订单日期" prop="ddDate">
        <el-date-picker clearable v-model="queryParams.ddDate"
                        type="date" value-format="yyyy-MM-dd" placeholder="请选择订单日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="需求日期" prop="subDate">
        <el-date-picker clearable v-model="queryParams.subDate"
                        type="date" value-format="yyyy-MM-dd" placeholder="请选择需求日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="税率" prop="tax">
        <el-input v-model="queryParams.tax" placeholder="请输入税率"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="客户id" prop="customerId">
        <el-input v-model="queryParams.customerId" placeholder="请输入客户id"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input v-model="queryParams.customerName" placeholder="请输入客户名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="是否打款" prop="isBuy">
        <el-input v-model="queryParams.isBuy" placeholder="请输入是否打款"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="订单金额" prop="money">
        <el-input v-model="queryParams.money" placeholder="请输入订单金额"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="剩余欠款" prop="shengyu">
        <el-input v-model="queryParams.shengyu" placeholder="请输入剩余欠款"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="税额" prop="shuie">
        <el-input v-model="queryParams.shuie" placeholder="请输入税额"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="总数量" prop="counts">
        <el-input v-model="queryParams.counts" placeholder="请输入总数量"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="总吨位" prop="dunwei">
        <el-input v-model="queryParams.dunwei" placeholder="请输入总吨位"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="供应商id" prop="supplierId">
        <el-input v-model="queryParams.supplierId" placeholder="请输入供应商id"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input v-model="queryParams.deptId" placeholder="请输入部门ID"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="部门名称" prop="deptName">
        <el-input v-model="queryParams.deptName" placeholder="请输入部门名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户id"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="业务员" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入业务员"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="审核状态" prop="state">
        <el-input v-model="queryParams.state" placeholder="请输入审核状态"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="银行行号" prop="hanghao">
        <el-input v-model="queryParams.hanghao" placeholder="请输入银行行号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="银行账号" prop="zhanghao">
        <el-input v-model="queryParams.zhanghao" placeholder="请输入银行账号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="开户行" prop="kaihuhang">
        <el-input v-model="queryParams.kaihuhang" placeholder="请输入开户行"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="运费" prop="yunfei">
        <el-input v-model="queryParams.yunfei" placeholder="请输入运费"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="到货金额" prop="daohuo">
        <el-input v-model="queryParams.daohuo" placeholder="请输入到货金额"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="开票总金额" prop="kaipiao">
        <el-input v-model="queryParams.kaipiao" placeholder="请输入开票总金额"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="剩余开票额" prop="shengyukp">
        <el-input v-model="queryParams.shengyukp" placeholder="请输入剩余开票额"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="采购id" prop="mainId">
        <el-input v-model="queryParams.mainId" placeholder="请输入采购id"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="采购单号" prop="mainNo">
        <el-input v-model="queryParams.mainNo" placeholder="请输入采购单号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="送货人" prop="songhuoren">
        <el-input v-model="queryParams.songhuoren" placeholder="请输入送货人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="送货人电话" prop="songhuotel">
        <el-input v-model="queryParams.songhuotel" placeholder="请输入送货人电话"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="送货人开户行" prop="songkaihuhang">
        <el-input v-model="queryParams.songkaihuhang" placeholder="请输入送货人开户行"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="送货人账号" prop="songzhanghao">
        <el-input v-model="queryParams.songzhanghao" placeholder="请输入送货人账号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="是否打款供应商" prop="isSupplier">
        <el-input v-model="queryParams.isSupplier" placeholder="请输入是否打款供应商"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="是否打款送货人" prop="isSong">
        <el-input v-model="queryParams.isSong" placeholder="请输入是否打款送货人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['develop:LvDaohuo:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                   @click="handleUpdate" v-hasPermi="['develop:LvDaohuo:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
          <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                     v-hasPermi="['develop:LvDaohuo:remove']">删除
          </el-button>
        </el-popconfirm>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExport" v-hasPermi="['develop:LvDaohuo:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="${comment}" align="center" prop="id"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="订单编号" align="center" prop="nos"/>
      <el-table-column label="订单日期" align="center" prop="ddDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ddDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="需求日期" align="center" prop="subDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.subDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采购类型" align="center" prop="type"/>
      <el-table-column label="业务类型" align="center" prop="ywType"/>
      <el-table-column label="税率" align="center" prop="tax"/>
      <el-table-column label="客户id" align="center" prop="customerId"/>
      <el-table-column label="客户名称" align="center" prop="customerName"/>
      <el-table-column label="是否打款" align="center" prop="isBuy"/>
      <el-table-column label="订单金额" align="center" prop="money"/>
      <el-table-column label="剩余欠款" align="center" prop="shengyu"/>
      <el-table-column label="税额" align="center" prop="shuie"/>
      <el-table-column label="总数量" align="center" prop="counts"/>
      <el-table-column label="总吨位" align="center" prop="dunwei"/>
      <el-table-column label="供应商id" align="center" prop="supplierId"/>
      <el-table-column label="供应商名称" align="center" prop="supplierName"/>
      <el-table-column label="部门ID" align="center" prop="deptId"/>
      <el-table-column label="部门名称" align="center" prop="deptName"/>
      <el-table-column label="用户id" align="center" prop="userId"/>
      <el-table-column label="业务员" align="center" prop="userName"/>
      <el-table-column label="审核状态" align="center" prop="state"/>
      <el-table-column label="发票文件" align="center" prop="fpfile"/>
      <el-table-column label="银行行号" align="center" prop="hanghao"/>
      <el-table-column label="银行账号" align="center" prop="zhanghao"/>
      <el-table-column label="开户行" align="center" prop="kaihuhang"/>
      <el-table-column label="运费" align="center" prop="yunfei"/>
      <el-table-column label="到货金额" align="center" prop="daohuoMoney"/>
      <el-table-column label="开票总金额" align="center" prop="kaipiao"/>
      <el-table-column label="剩余开票额" align="center" prop="shengyukp"/>
      <el-table-column label="采购id" align="center" prop="mainId"/>
      <el-table-column label="采购单号" align="center" prop="mainNo"/>
      <el-table-column label="材质单文件" align="center" prop="caizhidan"/>
      <el-table-column label="过磅单文件" align="center" prop="guobangdan"/>
      <el-table-column label="直发货回执单" align="center" prop="zhifahuo"/>
      <el-table-column label="送货人" align="center" prop="songhuoren"/>
      <el-table-column label="送货人电话" align="center" prop="songhuotel"/>
      <el-table-column label="送货人开户行" align="center" prop="songkaihuhang"/>
      <el-table-column label="送货人账号" align="center" prop="songzhanghao"/>
      <el-table-column label="是否打款供应商" align="center" prop="isSupplier"/>
      <el-table-column label="是否打款送货人" align="center" prop="isSong"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:LvDaohuo:edit']">修改
          </el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:LvDaohuo:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <lvDaohuo-form ref="form" @ok="getList"></lvDaohuo-form>
  </div>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import LvDaohuoForm from '@/views/develop/lvDaohuo/module/LvDaohuoForm'

export default {
  name: "LvDaohuoList",
  components: {
    LvDaohuoForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 到货单表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nos: null,
        ddDate: null,
        subDate: null,
        type: null,
        ywType: null,
        tax: null,
        customerId: null,
        customerName: null,
        isBuy: null,
        money: null,
        shengyu: null,
        shuie: null,
        counts: null,
        dunwei: null,
        supplierId: null,
        supplierName: null,
        deptId: null,
        deptName: null,
        userId: null,
        userName: null,
        state: null,
        fpfile: null,
        hanghao: null,
        zhanghao: null,
        kaihuhang: null,
        yunfei: null,
        daohuo: null,
        kaipiao: null,
        shengyukp: null,
        mainId: null,
        mainNo: null,
        caizhidan: null,
        guobangdan: null,
        zhifahuo: null,
        songhuoren: null,
        songhuotel: null,
        songkaihuhang: null,
        songzhanghao: null,
        isSupplier: null,
        isSong: null
      },
      url: {
        list: '/lvDaohuo/lvDaohuo/list',
        remove: '/lvDaohuo/lvDaohuo/',
        export: '/lvDaohuo/lvDaohuo/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
    /** 查询到货单列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `lvDaohuo_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
